package com.wang.android.library.network.eventbus;

import com.wang.android.library.frame.persenter.WBasePresenter;

/**
 * @author Wanghuanyu
 * @date 2017/3/8 8:52
 * @description  网络事件总线（基于网络数据回调页面）
 * @classname WHttpEventBean
 * @version 1.0.0
 * @修改者
 * @时间
 */
public class WHttpEventBean<T> {
    private WHttpStatus wHttpStatus;//网络请求状态
    private WBasePresenter wBasePresenter;//VM控制器（用于校验EventBus接受）
    private String method;//方法名
    private String message;//Toast提示消息（Server提供）
    private T obj;//module（存储data）

    public WHttpEventBean(WBasePresenter wBasePresenter) {
        this.wBasePresenter = wBasePresenter;
    }

    public WHttpEventBean() {
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public WHttpStatus getwHttpStatus() {
        return wHttpStatus;
    }

    public void setwHttpStatus(WHttpStatus wHttpStatus) {
        this.wHttpStatus = wHttpStatus;
    }

    public WBasePresenter getwBasePresenter() {
        return wBasePresenter;
    }

    public void setwBasePresenter(WBasePresenter wBasePresenter) {
        this.wBasePresenter = wBasePresenter;
    }

    public T getObj() {
        return obj;
    }

    public void setObj(T obj) {
        this.obj = obj;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * 校验事件类型
     * @param wBasePresenter
     * @param method
     * @return
     */
    public boolean checkOutEventBus(WBasePresenter wBasePresenter,String method){
        if(this.wBasePresenter == wBasePresenter && this.method.equals(method)){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 校验网络请求是否成功（View只关注成功或失败，失败原因不做区分）
     * @return
     */
    public boolean onSuccess(){
        if(this.wHttpStatus.equals(WHttpStatus.HTTPSUCCESS) ){
            return true;
        }else{
            return false;
        }
    }
}
